<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- 将四个方向的距离都设置成0，然后使用margin: auto;也可以实现 -->
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }

        #wrap {
            width: 500px;
            height: 500px;
            background: grey;
            position: relative;
        }

        #box {
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto;

            width: 200px;
            height: 200px;
            background: deeppink;
        }
    </style>
</head>

<body>
    <div id="wrap">
        <div id="box"></div>
    </div>
</body>
<script type="text/javascript">
    // window.onload = function () {
    //     var box = document.getElementById('box');


    // }
</script>

</html>